Skip to main content

All Questions

3votes
2answers
1kviews

Sorted insert on a doubly linked list (HackerRank)

I've decided to do a simple linked list question to brush up my Java & CS. This is the solution for Given a reference to the head of a doubly-linked list and an integer, \$data\$ , create a ...
JaDogg's user avatar
  • 4,541
3votes
1answer
281views

Convert a Binary Tree to Doubly Linked List

Challenge Link on geeksforgeeks: Binary Tree to DLL Given a Binary Tree (BT), convert it to a Doubly Linked List(DLL) In-Place. The left and right pointers in nodes are to be used as previous ...
dfhwze's user avatar
5votes
2answers
503views

Leetcode #146. LRUCache solution in Java (Doubly Linked List + HashMap)

Problem Statement Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and put. get(key) - Get the value (will always be ...
Marko Cain's user avatar
2votes
2answers
2kviews

Swap Nodes in Pairs in singly linked list

Description: Given a linked list, swap every two adjacent nodes and return its head. For example, Given 1->2->3->4, you should return the list as 2->1->4->3. Your algorithm should use only ...
CodeYogi's user avatar
1vote
3answers
806views

Remove nth node from last position in linked list

Description: Given a linked list, remove the nth node from the end of list and return its head. Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the end, the ...
CodeYogi's user avatar
3votes
1answer
211views

Reverse singly linked list

Description: Given a linked list reverse it and return the new head. Code: ...
CodeYogi's user avatar
0votes
3answers
2kviews

Move last node of the linked list to the front

Description: Given a linked list move the last node to the front. For example: 10 20 30 40 -> 40 10 20 30 Code: ...
CodeYogi's user avatar
3votes
1answer
759views

Detecting a cycle in a linked list using Java

I'm solving HackerRank "Linked Lists: Detect a Cycle" challenge. A linked list is said to contain a cycle if any node is visited more than once while traversing the list. Complete the ...
justapilgrim's user avatar
7votes
2answers
985views

Singly Linked List "Strange sorting" exercise

I'm currently working through "Algorithms in java" by Robert Sedgewick (3rd edition, german version) on my own and am trying to solve one of the exercises there. One of these involves taking a ...
Philipp Doerner's user avatar
4votes
2answers
7kviews

Insert node in sorted doubly linked list

Description: Given a reference to the head of a doubly-linked list and an integer, create a new Node object having data value and insert it into a sorted linked list. Code: ...
CodeYogi's user avatar
9votes
1answer
2kviews

Get nth node from end in a linked list

Description: You’re given the pointer to the head node of a linked list and a specific position. Counting backwards from the tail node of the linked list, get the value of the node at the given ...
CodeYogi's user avatar
3votes
1answer
279views

Code to merge sorted linked lists in java

Since I am using Hackerrank codepair, I have to resort to inner classes. Please review the code and let me know if this can be improved. ...
Vijay's user avatar
5votes
2answers
5kviews

Poisonous Plants

I have solved the following problem. My code works but Hackerrank says that I can do faster: There are plants in a garden. Each of these plants has been added with some amount of pesticide. After ...
BlackM's user avatar
4votes
4answers
3kviews

Given only a pointer to a node to be deleted in a singly linked list, how do you delete it?

Example: If a linkedlist list contains 10->20->30->40, and 2nd node has to be deleted then the output should be 10->30->40 This question is attributed to Geeksforgeeks. Looking for code-review, ...
JavaDeveloper's user avatar

close